package com.dbsop.operation.query.rest;

import com.dbsop.domain.AbsConditionQuery;
import com.dbsop.domain.EsCondition;
import com.dbsop.domain.rest.EsRestCondition;
import com.dbsop.domain.rest.res.RestUtils;
import com.dbsop.domain.transport.EsTransportCondition;
import com.dbsop.domain.transport.query.ConditionQuery;
import com.dbsop.domain.transport.res.TransportUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;

import java.util.List;

/**
 *
 */
public class RestBoolQueries {

    private EsCondition esCondition;

    private BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();

    private  List<ConditionQuery> conditions ;

    public RestBoolQueries(EsRestCondition esRestCondition) {
        this.esCondition = esRestCondition;
        conditions  = esCondition.getConditions();
        init();
    }

    public BoolQueryBuilder getBoolQueryBuilder() {
        return boolQueryBuilder;
    }

    private void init(){
        this.boolQueryBuilder = paringCondition(conditions);
    }

    /**
     * 条件转换
     * @param conditionQueries
     */
    private <T extends AbsConditionQuery> BoolQueryBuilder paringCondition(List<T> conditionQueries){
        return RestUtils.subBoolQueryBuilder(conditionQueries);
    }





}
